package com.bdmc.report.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.bdmc.common.core.page.TableDataInfo;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.report.domain.vo.ReportCarOilCostVo;
import org.springframework.stereotype.Service;
import com.bdmc.common.core.mybatisplus.core.ServicePlusImpl;
import com.bdmc.report.domain.bo.ReportCarStopBo;
import com.bdmc.report.domain.vo.ReportCarStopVo;
import com.bdmc.report.domain.ReportCarStop;
import com.bdmc.report.mapper.ReportCarStopMapper;
import com.bdmc.report.service.IReportCarStopService;

import java.util.List;
import java.util.Collection;

/**
 * 怠速时长以及油耗Service业务层处理
 *
 * @author bdmc
 * @date 2022-08-09
 */
@Service
public class ReportCarStopServiceImpl extends ServicePlusImpl<ReportCarStopMapper, ReportCarStop, ReportCarStopVo> implements IReportCarStopService {

    @Override
    public ReportCarStopVo queryById(Long stopId){
        return getVoById(stopId);
    }

    @Override
    public TableDataInfo<ReportCarStopVo> queryPageList(ReportCarStopBo bo, PageQuery pageQuery) {
        return TableDataInfo.build(baseMapper.mySelectPage(pageQuery.build(),bo));
    }

    @Override
    public TableDataInfo<ReportCarStopVo> mySelectPage(ReportCarStopBo bo, PageQuery pageQuery) {
        return TableDataInfo.build(baseMapper.mySelectPage(pageQuery.build(),bo));
    }

    @Override
    public List<ReportCarStopVo> queryList(ReportCarStopBo bo) {
        return baseMapper.mySelectPage(bo);
    }

    @Override
    public List<ReportCarOilCostVo> queryOilList(ReportCarStopBo bo) {
        return baseMapper.mySelectOilPage(bo);
    }


    @Override
    public Boolean insertByBo(ReportCarStopBo bo) {
        ReportCarStop add = BeanUtil.toBean(bo, ReportCarStop.class);
        validEntityBeforeSave(add);
        boolean flag = save(add);
        if (flag) {
            bo.setStopId(add.getStopId());
        }
        return flag;
    }

    @Override
    public Boolean updateByBo(ReportCarStopBo bo) {
        ReportCarStop update = BeanUtil.toBean(bo, ReportCarStop.class);
        validEntityBeforeSave(update);
        return updateById(update);
    }

    /**
     * 保存前的数据校验
     *
     * @param entity 实体类数据
     */
    private void validEntityBeforeSave(ReportCarStop entity){
        //TODO 做一些数据校验,如唯一约束
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return removeByIds(ids);
    }
}
